package sz.szsmk.citizencard.mvp.presenter;

import android.widget.Toast;

import javax.inject.Inject;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.QueryMetroExitInfoReq;
import sz.szsmk.citizencard.model.network.bean.response.QueryMetroExitInfoRes;
import sz.szsmk.citizencard.mvp.contract.ISubwaySiteDetailContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/4 9:33
 * description:
 */
public class SubwaySiteDetailPresenter extends IBasePresenter
        implements ISubwaySiteDetailContact.ISubwaySiteDetailPresenter<ISubwaySiteDetailContact.ISubwaySiteDetailView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public SubwaySiteDetailPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void getSiteDetailData(String site) {
        QueryMetroExitInfoReq queryMetroExitInfoReq = new QueryMetroExitInfoReq();
        queryMetroExitInfoReq.setStand_key_name(site);
        mNetworkDateSource.queryMetroExitInfo(queryMetroExitInfoReq, new SubscribeResult<QueryMetroExitInfoRes>() {
            @Override
            protected void onOk(QueryMetroExitInfoRes response) {
                ((ISubwaySiteDetailContact.ISubwaySiteDetailView) mView).getSiteDetailDataSucc(response);
            }

            @Override
            protected void onFailure(QueryMetroExitInfoRes response) {
                super.onFailure(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });


    }
}
